package com.hs.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hs.entity.dto.Comment;
import com.hs.entity.dto.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Select("SELECT " +
            "o.id, o.user_id, o.team_id, o.type_id, " +
            "o.start_location, o.end_location, " +
            "o.start_time, o.create_time, " +
            "o.is_help, o.order_type, o.money, o.status, " +
            "t.team_name, t.team_img, " +
            "u.username, u.avatar, " +
            "tt.team_type_name, tt.team_type_img " +
            "FROM orders o " +
            "LEFT JOIN teams t ON o.team_id = t.id " +
            "LEFT JOIN users u ON o.user_id = u.id " +
            "LEFT JOIN team_types tt ON o.type_id = tt.id " +
            "${ew.customSqlSegment}")
    List<Order> selectListWithTeamAndUser(@Param("ew") QueryWrapper<Order> queryWrapper);

    @Select("SELECT " +
            "o.id, o.user_id, o.team_id, o.type_id, " +
            "o.start_location, o.end_location, " +
            "o.start_time, o.create_time, " +
            "o.is_help, o.order_type, o.money, o.status, " +
            "t.team_name, t.team_img, " +
            "u.username, u.avatar, " +
            "tt.team_type_name, tt.team_type_img " +
            "FROM orders o " +
            "LEFT JOIN teams t ON o.team_id = t.id " +
            "LEFT JOIN users u ON o.user_id = u.id " +
            "LEFT JOIN team_types tt ON o.type_id = tt.id " +
            "WHERE o.id = #{id}")
    Order selectOrderById(@Param("id") Integer id);
}